﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LView.CMS.ViewModels;
using Microsoft.AspNetCore.Mvc;
using LView.CMS.IServices;
using LView.CMS.Core.Helper;
using LView.CMS.IServices;

namespace LView.CMS.Site.Controllers
{
    public class CourseController : Controller
    {
        private readonly IAssetsService _service;
        private readonly ICourseService _courseService;
        public CourseController(IAssetsService service, ICourseService courseService)
        {
            _service = service;
            _courseService = courseService;
        }

        public IActionResult Index()
        {
            ViewData["FileList"] = _courseService.GetFileList();
            ViewData["TaskList"] = _courseService.GetTaskList();
            ViewData["ExamList"] = _courseService.GetExamList();
            return View();
        }

        [HttpPost]
        public async Task<string> GetTask(string taskId)
        {
            var task = await _courseService.GetCurrentTask(taskId);
            return JsonHelper.ObjectToJSON(task.Category);
        }

        [HttpPost]
        [Route("/Course/Add")]
        public async Task<string> AddAsync([FromForm] CourseAddOrModify input)
        {
            var result = new BaseResult();
            result = await _courseService.AddCourseAsync(input);
            return JsonHelper.ObjectToJSON(result);
        }
    }
}
